package dyyx.bladex;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

public class BladexServer {

	
    static final int port = Integer.parseInt(System.getProperty("port", "7030"));

	
	public static void main(String[] args) throws Exception {
		
		System.out.println("bladex server start "+System.currentTimeMillis()+",port="+port);

		
       

        // Configure the server.
        //  NioEventLoopGroup(int nThreads) 
        // int DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt("io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
        // Runtime.getRuntime().availableProcessors() * 2
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        
        //  ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup) 
        // the parent (acceptor) and the child (client)
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.option(ChannelOption.SO_BACKLOG, 1024);
            b.group(bossGroup, workerGroup)
             .channel(NioServerSocketChannel.class)
             .handler(new LoggingHandler(LogLevel.INFO))
             .childHandler(new BladexServerInit());
             //.childHandler(new ServerInitializer(sslCtx));

            Channel ch = b.bind(port).sync().channel();

           
            ch.closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }

		
	
	

	
}
